﻿CREATE PROCEDURE ProductReview_Update
	@productReviewId int,
	@body varchar(8000),
	@rating int,
	@subject varchar(50),
	@productId int,
	@userName varchar(50),
	@userEmail varchar(50)
AS
	SET NOCOUNT ON
	update ProductReviews
	Set
		Body = @body,
		Rating = @rating,
		Subject = @subject,
		ProductId = @productId,
		UserName = @userName,
		UserEmail = @userEmail,
		EditedDate = GetDate()
	where
		ProductReviewId = @productReviewId
		
	declare @averageRating float
	select @averageRating = avg (Rating) from ProductReviews where ProductId = @productId
	
	update Products set
		Rating = @averageRating
	where ProductId = @productId
	RETURN


